package com.car.loan.project.xr.controller;

import com.car.loan.framework.aspectj.lang.annotation.DataStatus;
import com.car.loan.framework.aspectj.lang.annotation.Log;
import com.car.loan.framework.aspectj.lang.enums.BusinessType;
import com.car.loan.framework.web.domain.AjaxResult;
import com.car.loan.project.xr.service.ILoanService;
import com.car.loan.project.xr.service.impl.FileAuditService;
import com.car.loan.project.xr.util.bo.business.LoanBaseInfo;
import com.car.loan.project.xr.util.select.LoanBasePageParam;
import com.car.loan.project.xr.util.vo.LoanContractAuditVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author huangding
 * @description
 * @date 2019/12/8 10:33
 */
@RestController
@RequestMapping("xr/file/audit")
@Api(value = "档案审核", tags = "车贷业务-档案审核")
public class FileAuditController {

    @Autowired
    private ILoanService loanService;


    @Autowired
    private FileAuditService fileAuditService;


    @PreAuthorize("@ss.hasPermi('file:audit:list')")
    @GetMapping("list")
    @ApiOperation(value = "获取档案审核列表", response = LoanBaseInfo.class, responseContainer = "list")
    @DataStatus(loanStatusEnum = com.car.loan.common.enums.LoanStatusEnum.FILE_AUDIT_STATUS)
    public AjaxResult applyList(@Valid LoanBasePageParam loanBasePageParam) {
        return AjaxResult.success(loanService.page(loanBasePageParam));
    }


    @PreAuthorize("@ss.hasPermi('file:audit:query')")
    @GetMapping("{loanId}")
    @ApiOperation(value = "获取档案审核详情", response = LoanContractAuditVo.class)
    public AjaxResult saveApply(@PathVariable Long loanId) {
        return AjaxResult.success(loanService.getContractAuditDetail(loanId));
    }


    @PreAuthorize("@ss.hasPermi('file:audit:audit')")
    @PostMapping("getFileNo/{loanId}")
    @Log(title = "获取档案审核编号", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "获取档案审核编号")
    public AjaxResult getFileNo(@PathVariable Long loanId) {
        return AjaxResult.success(fileAuditService.getFileNo(loanId));
    }

    @PreAuthorize("@ss.hasPermi('file:audit:audit')")
    @PostMapping("audit/{loanId}")
    @Log(title = "档案审核", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "档案审核", notes = "档案提交会返回档案编号")
    public AjaxResult audit(@PathVariable Long loanId) {
        return fileAuditService.audit(loanId);
    }

}
